<html>
<head><meta charset="utf-8"><title>parsing traits, types and generic parameters · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html">parsing traits, types and generic parameters</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="161629779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161629779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161629779">(Mar 25 2019 at 10:21)</a>:</h4>
<p>Attempting to figure out where types &amp; traits are actually allowed in rust, and figuring out how we are currently parsing things.</p>
<p>For example in <code>Box&lt;T + 'f&gt;</code>, is there a reason the parsed <code>PathType</code> contains the lifetime, rather than it being another separate item.</p>
<p>Currently this looks like:</p>
<div class="codehilite"><pre><span></span>PATH_TYPE@[12; 23)
  PATH@[12; 23)
    PATH_SEGMENT@[12; 23)
      NAME_REF@[12; 15)
        IDENT@[12; 15) &quot;Box&quot;
      TYPE_ARG_LIST@[15; 23)
        L_ANGLE@[15; 16)
        TYPE_ARG@[16; 22)
          PATH_TYPE@[16; 22)
            PATH@[16; 17)
              PATH_SEGMENT@[16; 17)
                NAME_REF@[16; 17)
                  IDENT@[16; 17) &quot;T&quot;
            WHITESPACE@[17; 18)
            PLUS@[18; 19)
            WHITESPACE@[19; 20)
            LIFETIME@[20; 22) &quot;&#39;f&quot;
        R_ANGLE@[22; 23)
</pre></div>


<p>I would expect it probably to be something like:</p>
<div class="codehilite"><pre><span></span>    ...
        TYPE_ARG@[16; 22)
          PATH_TYPE@[16; 22)
            PATH@[16; 17)
              PATH_SEGMENT@[16; 17)
                NAME_REF@[16; 17)
                  IDENT@[16; 17) &quot;T&quot;
        WHITESPACE@[17; 18)
        PLUS@[18; 19)
        WHITESPACE@[19; 20)
        TYPE_ARG@...:
          LIFETIME@[20; 22) &quot;&#39;f&quot;
        R_ANGLE@[22; 23)
</pre></div>


<p>With the <code>LIFETIME</code> being outside the <code>PATH_TYPE</code>.</p>
<p>Once I figure out where things are actually allowed, I'd like to attempt to fix the parser and maybe add some additional grammar for types/traits if it makes sense.parsing traits, types and generic parameters</p>



<a name="161630796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161630796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161630796">(Mar 25 2019 at 10:36)</a>:</h4>
<p>So this is the confusing example. This is actually <code>Box&lt;dyn T + 'f&gt;</code>, and <code>+'f</code> is a part of a <code>dyn</code> type</p>



<a name="161630812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161630812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161630812">(Mar 25 2019 at 10:36)</a>:</h4>
<p>in <code>dyn</code>, the first component is restricted to be a path, referring to the trait</p>



<a name="161630818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161630818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161630818">(Mar 25 2019 at 10:37)</a>:</h4>
<p>aha!</p>



<a name="161630836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161630836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161630836">(Mar 25 2019 at 10:37)</a>:</h4>
<p>and <code>dyn</code> being optional is what creates confustion here</p>



<a name="161630850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161630850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161630850">(Mar 25 2019 at 10:37)</a>:</h4>
<p>That makes sense</p>



<a name="161630966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161630966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161630966">(Mar 25 2019 at 10:39)</a>:</h4>
<p>A similar case of type-trait confustion happens in impls</p>



<a name="161630995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161630995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161630995">(Mar 25 2019 at 10:40)</a>:</h4>
<p>In <code>impl X for Y</code> and <code>impl X</code>, the <code>X</code> can be either a trait or a type</p>



<a name="161631046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631046">(Mar 25 2019 at 10:40)</a>:</h4>
<p>I wish we could make this separation precise on the grammar level</p>



<a name="161631156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631156">(Mar 25 2019 at 10:42)</a>:</h4>
<p>and .... this is probably the first time I myself uderstand what's going on here. The<code> dyn</code> is the key</p>



<a name="161631370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631370">(Mar 25 2019 at 10:45)</a>:</h4>
<p>hmm, what about <code>struct S&lt;T: 'a + ?Sized + (Copy)&gt;</code> I imagine here the bounds should be flattened, currently the <code>PathTypes</code> are nested</p>



<a name="161631445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631445">(Mar 25 2019 at 10:46)</a>:</h4>
<p>It gets even more confusing when you change where the lifetime is</p>



<a name="161631531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631531">(Mar 25 2019 at 10:48)</a>:</h4>
<p>or if you add more bounds</p>



<a name="161631552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631552">(Mar 25 2019 at 10:49)</a>:</h4>
<p>So, <code>Trait1 + Trait2 + lifetime1 + lifetime2</code> is a <code>TraitGroup</code></p>



<a name="161631566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631566">(Mar 25 2019 at 10:49)</a>:</h4>
<p>the syntax for <code>dyn</code> types is <code>dyn: TraitGroup</code></p>



<a name="161631569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631569">(Mar 25 2019 at 10:49)</a>:</h4>
<p><code>dyn TraitGroup</code></p>



<a name="161631573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631573">(Mar 25 2019 at 10:49)</a>:</h4>
<p>the syntax for bound is <code>Type: TraitGroup</code></p>



<a name="161631627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631627">(Mar 25 2019 at 10:50)</a>:</h4>
<p>and yeah, the <code>TraitGroup</code> should be flat</p>



<a name="161631650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631650">(Mar 25 2019 at 10:50)</a>:</h4>
<p>I'll see about fixing it, after that where clauses should kinda work</p>



<a name="161631695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161631695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161631695">(Mar 25 2019 at 10:51)</a>:</h4>
<p>hmm, <code>TraitGroup</code> can contain <code>Lifetime</code> and <code>TypeRef</code> ?</p>



<a name="161632675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161632675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161632675">(Mar 25 2019 at 11:08)</a>:</h4>
<p>yeah</p>



<a name="161736249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736249">(Mar 26 2019 at 06:46)</a>:</h4>
<p>In  <code>trait T&lt;U&gt;: Hash + Clone where U: Copy {}</code>, is <code>Hash + Clone</code> a <code>TraitGroup</code> as well ?</p>



<a name="161736501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736501">(Mar 26 2019 at 06:52)</a>:</h4>
<p>I think so!</p>



<a name="161736759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736759">(Mar 26 2019 at 07:00)</a>:</h4>
<p>hmm, in <code>trait X&lt;U: Debug + Display&gt;</code> should the <code>&lt;U: Debug + Display&gt;</code> be parsed as:</p>
<div class="codehilite"><pre><span></span>TYPE_PARAM_LIST@[49; 69)
  L_ANGLE@[49; 50)
  TYPE_PARAM@[50; 68)
    NAME@[50; 51)
      IDENT@[50; 51) &quot;U&quot;
    COLON@[51; 52)
    WHITESPACE@[52; 53)
  TRAIT_GROUP.. // new
    PATH_TYPE@[53; 68)
      PATH@[53; 58)
        PATH_SEGMENT@[53; 58)
          NAME_REF@[53; 58)
            IDENT@[53; 58) &quot;Debug&quot;
    WHITESPACE@[58; 59)
    PLUS@[59; 60)
    WHITESPACE@[60; 61)
    PATH_TYPE@[61; 68)
      PATH@[61; 68)
          PATH_SEGMENT@[61; 68)
          NAME_REF@[61; 68)
              IDENT@[61; 68) &quot;Display&quot;
</pre></div>


<p>basically the typeparam list can contain the typeparam + optional trait group</p>



<a name="161736803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736803">(Mar 26 2019 at 07:00)</a>:</h4>
<p>I think <code>: TraitGroup</code> might be grouped under a <code>Bound</code> as well</p>



<a name="161736834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736834">(Mar 26 2019 at 07:01)</a>:</h4>
<p>It might also be a good idea to ping grammar WG on discord about naming and general structure in this area</p>



<a name="161736886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736886">(Mar 26 2019 at 07:02)</a>:</h4>
<p>IIRC, currently the gramamr closely mirrors what is implemented in rustc</p>



<a name="161736889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736889">(Mar 26 2019 at 07:02)</a>:</h4>
<p>but I think we can do much better here</p>



<a name="161736896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/161736896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#161736896">(Mar 26 2019 at 07:03)</a>:</h4>
<p>Yeah I think there is room for improvement</p>



<a name="162123914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/162123914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#162123914">(Mar 30 2019 at 14:45)</a>:</h4>
<p>Added a draft pr regarding this: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/1077" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/1077">https://github.com/rust-analyzer/rust-analyzer/pull/1077</a></p>



<a name="164372200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/164372200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#164372200">(Apr 28 2019 at 06:13)</a>:</h4>
<p>I am trying to implement default param in GenericParam, something like <code>struct Foo&lt;T=u8&gt; {_v: T}</code>. Currently it is parsed as :</p>
<div class="codehilite"><pre><span></span>STRUCT_DEF@[14; 45)
    STRUCT_KW@[14; 20) &quot;struct&quot;
    WHITESPACE@[20; 21) &quot; &quot;
    NAME@[21; 24)
      IDENT@[21; 24) &quot;Foo&quot;
    TYPE_PARAM_LIST@[24; 30)
      L_ANGLE@[24; 25) &quot;&lt;&quot;
      TYPE_PARAM@[25; 29)
        NAME@[25; 26)
          IDENT@[25; 26) &quot;T&quot;
        EQ@[26; 27) &quot;=&quot;
        PATH_TYPE@[27; 29)
          PATH@[27; 29)
            PATH_SEGMENT@[27; 29)
              NAME_REF@[27; 29)
                IDENT@[27; 29) &quot;u8&quot;
      R_ANGLE@[29; 30) &quot;&gt;&quot;
</pre></div>


<p>Do we want to introduce another syntax node (something like <code>DEFAULT_TYPE_PARAM</code>) for that ? Or we can use that PATH_TYPE directly?</p>



<a name="164384856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/164384856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#164384856">(Apr 28 2019 at 12:28)</a>:</h4>
<p>I think we don't need an extra node here</p>



<a name="164384859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/164384859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#164384859">(Apr 28 2019 at 12:28)</a>:</h4>
<p>But we should definitelly add an <code>default</code> method to <code>TypeParam</code></p>



<a name="164387892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/164387892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#164387892">(Apr 28 2019 at 13:43)</a>:</h4>
<p>My concern is that if we use PATH_TYPE, it will be confused with other syntax. If not, then it’s good. <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="164388068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/parsing%20traits%2C%20types%20and%20generic%20parameters/near/164388068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/parsing.20traits.2C.20types.20and.20generic.20parameters.html#164388068">(Apr 28 2019 at 13:46)</a>:</h4>
<p>As long as we have well-typed accessor methods on <code>TypeParam</code>, I think there won't be any confustion</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>